package com.dg.river.core.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dg.river.R;

/**
 * @作者：Hututu
 * @时间：2023/6/26 10:07
 * @描述：内容描述
 * @修改：修改内容
 * @Version:1.0
 */
public class PayFailureDialog extends Dialog {

    private static TextView tvRetry;
    private static TextView tvBack;

    private static PayFailureDialog dialog;

    public PayFailureDialog(Context context) {
        super(context);
    }

    public PayFailureDialog(Context context, int theme) {
        super(context, theme);
    }

    public interface OnPayFailureClickListener {
        void onPayBack(PayFailureDialog dialog);

        void onPayRetry(PayFailureDialog dialog);
    }

    public static class Builder {
        private Context context;
        private boolean cancel = false;
        public OnPayFailureClickListener listener;

        public Builder(Context context) {
            this.context = context;
        }

        public PayFailureDialog.Builder setListener(OnPayFailureClickListener listener) {
            this.listener = listener;
            return this;
        }

        /**
         * 设置是否能够取消
         *
         * @param bool
         * @return
         */
        public PayFailureDialog.Builder setCancel(boolean bool) {
            this.cancel = bool;
            return this;
        }

        public PayFailureDialog create() {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            dialog = new PayFailureDialog(context, R.style.dialog_message_normal_white);
            View layout = inflater.inflate(R.layout.dialog_pay_failure, null);
            dialog.addContentView(layout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            dialog.getWindow().setWindowAnimations(R.style.dialogWindowAnim);

            tvBack = layout.findViewById(R.id.tvBack);
            tvRetry = layout.findViewById(R.id.tvRetry);
            tvBack.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.onPayBack(dialog);
                }
            });
            tvRetry.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.onPayRetry(dialog);
                }
            });
            dialog.setContentView(layout);
            if (!cancel) {
                dialog.setCancelable(false);
            } else {
                dialog.setCancelable(true);
            }
            return dialog;
        }
    }
}
